<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Usuario
 *
 * @author gilmario
 */

namespace App\Models;

use SON\DB\Table;

class Beneficiario extends Table {

    protected $table = 'beneficiario';

    public function adiciona($nome) {
        try {
            $this->db->beginTransaction();
            $query = "INSERT INTO {$this->table}(nome) values ('{$nome}') ";
            $this->db->query($query);
            $this->db->commit();
        } catch (Exception $ex) {
            echo $ex;
            $this->db->roolBack();
        }
    }

    public function atualiza($id, $nome) {
        try {
            $this->db->beginTransaction();
            $query = "UPDATE {$this->table} SET nome ='{$nome}' WHERE id ={$id}; ";
            $this->db->query($query);
            $this->db->commit();
        } catch (Exception $ex) {
            echo $ex;
            $this->db->roolBack();
        }
    }

    protected function create() {
        try {
            $this->db->beginTransaction();
            $query = "CREATE TABLE IF NOT EXISTS {$this->table}(id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, nome VARCHAR(40)) ENGINE MYISAM";
            $this->db->query($query);
            $this->db->commit();
        } catch (Exception $ex) {
            echo $ex;
            $this->db->roolBack();
        }
    }

}
